﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SmartSpace.UI.Silverlight.Dynamic.DynamicRef;

namespace SmartSpace.UI.Silverlight.Dynamic.Commands
{
    public class DetailEntryCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            HyperlinkButton button = parameter as HyperlinkButton;
            if (button == null)
            {
                return;
            }

            DataInstance data = button.DataContext as DataInstance;
            if (data == null)
            {
                return;
            }

            ListTemplateView slView = button.Tag as ListTemplateView;
            if (slView != null)
            {
                slView.ShowDetail(data);

                ////待办工作
                //if (data.JobType == 1)
                //{
                //    //签收操作
                //    //TODO:自动签收操作
                //    PMFWebServiceSoapClient proxy = PMFModule.CreatePMFProxy();
                //    //不需要回调函数
                //    proxy.SignAsync(slView.Authentication.UserID, data.Id, data.ViewId, data);

                //    slView.SwitchView(new UpdateTemplateView(data.TableId, data.TableName, data.ViewId, data.Id));
                //}
                //else
                //{
                //    slView.SwitchView(new ReadTemplateView(data.TableId, data.TableName, data.ViewId, data.Id));
                //}

                return;
            }

            //UserControl container = data.Tag as UserControl;
            //if (container != null)
            //{
            //    object[] p = (object[])container.Tag;
            //    /*
            //    this.UserName,
            //    !isCanEdit,
            //    this.PrimaryTableId,
            //    this.PrimaryTableName,
            //    this.PrimaryViewId,
            //    this.PrimaryRecordId */
            //    if ((bool)p[1])
            //    {
            //        new ReadRelationRecordWindow(
            //            (string)p[0],
            //            data.TableName,
            //            data.ViewId,
            //            data.Id,
            //            (string)p[3],
            //            (int)p[4],
            //            (int)p[5]).Show();
            //    }
            //    else
            //    {
            //        UpdateRelationRecordWindow window = new UpdateRelationRecordWindow(
            //            (string)p[0],
            //            data.TableId,
            //            data.TableName,
            //            data.ViewId,
            //            data.Id,
            //            (int)p[2],
            //            (string)p[3],
            //            (int)p[4],
            //            (int)p[5]);
            //        window.Tag = container;
            //        window.Closed += new EventHandler(OnWindowClosed);
            //        window.Show();
            //    }
            //}
        }
    }
}
